package cn.tedu.property.management.controller;

import cn.tedu.property.management.pojo.dto.ChargeItemAddNewDTO;
import cn.tedu.property.management.pojo.dto.ChargeItemUpdateDTO;
import cn.tedu.property.management.pojo.vo.ChargeItemListItemVO;
import cn.tedu.property.management.pojo.vo.ChargeItemStandardVO;
import cn.tedu.property.management.service.IChargeItemService;
import cn.tedu.property.management.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理费用详情模块的控制器
 */
@RestController
@RequestMapping("/charge/item")
@Slf4j
@Api(tags = "费用项目模块")
public class ChargeItemController {

    @Autowired
    private IChargeItemService chargeItemService;

    @PostMapping("add-new")
    @ApiOperation("添加费用项目")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(ChargeItemAddNewDTO chargeItemAddNewDTO){
        log.debug("开始处理添加费用项目的请求，参数：{}", chargeItemAddNewDTO);
        chargeItemService.addNew(chargeItemAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除费用项目")
    @ApiOperationSupport(order = 200)
    private JsonResult deleteByChargeItemId(Long id){
        log.debug("开始处理删除费用项目的请求，参数：{}", id);
        chargeItemService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改费用项目")
    @ApiOperationSupport(order = 300)
    private JsonResult update(Long id , ChargeItemUpdateDTO chargeItemUpdateDTO){
        log.debug("开始处理删除费用项目的请求，id为：{} ，参数：{}", id ,chargeItemUpdateDTO);
        chargeItemService.updateById(id , chargeItemUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/select-item")
    @ApiOperation("根据项目id查询费用项目")
    @ApiOperationSupport(order = 400)
    private JsonResult<ChargeItemStandardVO> selectByItemID(Long id){
        log.debug("开始处理查询费用项目的请求，参数：{}", id);
        ChargeItemStandardVO chargeItemStandardVO = chargeItemService.selectById(id);
        return JsonResult.ok(chargeItemStandardVO);
    }

    @GetMapping("/select-owner")
    @ApiOperation("根据业主id查询费用项目")
    @ApiOperationSupport(order = 410)
    private JsonResult<List<ChargeItemListItemVO>> selectByOwnerId(Long ownerId){
        log.debug("开始处理查询费用项目的请求，参数：{}", ownerId);
        List<ChargeItemListItemVO> chargeItemListItemVOS = chargeItemService.selectByOwnerId(ownerId);
        return JsonResult.ok(chargeItemListItemVOS);
    }

    @GetMapping("/select-list")
    @ApiOperation("查询所有费用项目")
    @ApiOperationSupport(order = 420)
    private JsonResult<List<ChargeItemListItemVO>> selectByList(){
        log.debug("开始处理查询所有费用项目的请求，无参数");
        List<ChargeItemListItemVO> chargeItemListItemVOS = chargeItemService.selectList();
        return JsonResult.ok(chargeItemListItemVOS);
    }

    @GetMapping("/select-name")
    @ApiOperation("根据费用项目名称查询费用项目")
    @ApiOperationSupport(order = 430)
    private JsonResult<ChargeItemStandardVO> selectByName(String name){
        log.debug("开始处理根据费用项目名称查询费用项目的请求，参数：{}", name);
        ChargeItemStandardVO chargeItemStandardVO = chargeItemService.selectByName(name);
        return JsonResult.ok(chargeItemStandardVO);
    }

}
